package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/5.
 */
@HttpInlet(Conn.SHOW_SHOW_LIST)
public class ShowListGet extends BaseAsyGet<ShowListGet.ShowListEntity> {

    public String classid, region_id;
    public int page;

    public ShowListGet(AsyCallBack<ShowListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected ShowListEntity parser(JSONObject object) throws Exception {

        if (object.optInt("code") == 200) {

            JSONObject jsonObject_list = object.optJSONObject("list");

            ShowListEntity showListEntity = new ShowListEntity();
            showListEntity.total = jsonObject_list.optInt("total");
            showListEntity.current_page = jsonObject_list.optInt("current_page");
            showListEntity.per_page = jsonObject_list.optInt("per_page");

            JSONArray jsonArray = jsonObject_list.optJSONArray("data");

            for (int i = 0; i < jsonArray.length(); i++) {

                JSONObject jsonObject = jsonArray.optJSONObject(i);

                ShowEntity showEntity = new ShowEntity();
                showEntity.id = jsonObject.optString("id");
                showEntity.title = jsonObject.optString("title");
                showEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");
                showEntity.start_time = jsonObject.optString("start_time");
                showEntity.is_seat = jsonObject.optString("is_seat");
                showEntity.price_low = jsonObject.optString("price_low");
                showEntity.price_high = jsonObject.optString("price_high");
                showEntity.status = jsonObject.optString("status");
                showEntity.place_name = jsonObject.optString("place_name");

                showListEntity.list.add(showEntity);

            }

            return showListEntity;

        }

        TOAST = object.optString("message");

        return null;
    }

    public static class ShowListEntity {

        public List<ShowEntity> list = new ArrayList<>();
        public int total, current_page, per_page;

    }

    public static class ShowEntity {

        public String id, title, picurl, start_time, is_seat, price_low, price_high, status, place_name;

    }


//    {
//        "code": 200,
//            "message": "成功",
//            "list": {
//        "total": 6,   //总条数
//                "per_page": 10,  //每页条数
//                "current_page": 1, //当前页
//                "data": [
//        {
//            "id": 6,     //ID
//                "title": "开心麻花爆笑舞台剧《爷们儿》",      //标题
//                "picurl": "http://pimg.dmcdn.cn/perform/project/1083/108351_n.jpg",  //图片
//                "is_seat": 0, //	是否能选座 1可选 0不可 2待定
//                "status": 2,// 卖票的状态：0未开始1预定中2售票中3售完
//                "start_time": "2016-10-01", // 时间
//                "price_low": "200",  //最低价
//                "price_high": "600", //最高价
//                "place_name": "国际会展中心体育场" //场馆
//        }
//                        ]
//    }


}
